<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Login Form</title>
</head>

<body>
    <form>
        <label for="sn">学号：</label>
        <input type="text" name="sn" id="sn">
        <br>
        <label for="pswd">密码：</label>
        <input type="password" name="pswd" id="pswd">
        <input type="button" onclick="login()" value="提交">
        <input type="reset" value="重置">
        <br>
        <br>
        <label onclick="window.location.href='/register'">新用户注册</label>
        <label onclick="window.location.href='/forget'">忘记密码</label>

    </form>
</body>

<script>
    function login() {
        let sn = document.getElementById("sn").value;
        let pswd = document.getElementById("pswd").value;  
        fetch("/yanzhengLogin?sn="+sn+"&pswd="+pswd)
        .then( resp=>resp.json() )//解析
        .then(data=>{ //后续业务处理
            // data 就是后端发回来的数据，
            if (data !=null){ 
                  alert("欢迎你:"+data.Name);
                  localStorage.setItem("userinfo", JSON.stringify(data));
                  window.location.href = "/";
                //   document.getElementById("name").textContent = data.Name;
                //   document.getElementById("sex").textContent = data.Sex;
                //   document.getElementById("pswd").textContent = data.Pswd;
                //   document.getElementById("labelsn").textContent = data.Sn;
            
            }else {
                alert("登录失败")
            }
        })
    }
</script>